package com.runa.monitor.platinterface.extend.data.service;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.protobuf.ByteString;
import com.rn.smart.command.dto.Command;
import com.rn.smart.command.dto.meter.MeterBase;
import com.rn.smart.command.dto.meter.ReadMeter;
import com.rn.smart.command.dto.valve.ValveBase;
import com.rn.smart.command.dto.valve.contro.ControlValve;
import com.rn.smart.command.dto.valve.read.ReadValve;
import com.runa.monitor.comm.constants.ResultConstants;
import com.runa.monitor.comm.dto.newComm.AsynResult;
import com.runa.monitor.comm.entity.*;
import com.runa.monitor.comm.enums.NetEquTypeEnum;
import com.runa.monitor.comm.enums.NetServiceTypeEnum;
import com.runa.monitor.comm.enums.RegionTypeEnum;
import com.runa.monitor.comm.pojo.NBOrder;
import com.runa.monitor.comm.vo.CommNetEquipmentVO;
import com.runa.monitor.comm.vo.CommNodeEqu;
import com.runa.monitor.platinterface.extend.equ.EquInstructService;
import com.runa.monitor.platinterface.mqtt.MqttUtil;
import com.runa.monitor.platinterface.dispatch.conn.gen.*;
import com.runa.monitor.platinterface.dispatch.conn.gen.BuildValveControlOfOpenVO;
import com.runa.monitor.platinterface.dispatch.grpcComm.*;
import com.runa.monitor.platinterface.extend.equ.EquInstruct;
import com.runa.monitor.platinterface.netservice.equipment.NetEqu;
import com.runa.monitor.platinterface.platService.NetEquService;
import com.runa.monitor.platinterface.platService.RepositoryService;
import com.runa.monitor.platinterface.platService.InterfaceService;
import com.runa.monitor.platinterface.platService.MeterService;
import com.runa.monitor.platinterface.platService.pojo.GatewayDeviceParameter;
import com.runa.persistence.CollectionUtil;
import com.runa.persistence.cache.CommMeterCache;
import com.runa.persistence.cache.CommNetEquipmentCache;
import com.runa.persistence.cache.CommPanelCache;
import com.runa.persistence.cache.CommValveCache;
import com.runa.persistence.repository.*;
import com.runa.persistence.service.CommNbCmdService;
import com.runa.persistence.util.LogUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

@Slf4j
@Service
public class DataProcessService {
    @Resource
    private CommNetServiceRepository commNetServiceRepository;

    @Resource
    private MeterService meterService;

    @Resource
    private CommNbcmdRepository commNbcmdRepository;

    @Resource
    private NetEquService netEquService;

    @Resource
    private InterfaceService interfaceService;

    @Resource
    private RepositoryService repositoryService;
    @Resource
    private CommNbCmdService commNbCmdService;


    @Resource(name = "asyncRequestScheduler")
    private Executor executor;


    public Object addCommunicationProtocol(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        commNetServiceRepository.save(commNetServiceT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateCommunicationProtocol(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        commNetServiceRepository.save(commNetServiceT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deleteCommunicationProtocol(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        commNetServiceRepository.deleteById(commNetServiceT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getCommunicationProtocol(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commNetServiceRepository.getOne(commNetServiceT.getId()))))).build();
    }


    @Resource
    private CommMeterRepository commMeterRepository;

    public Object addMeter(String meter) {
        CommMeter meterT = JSON.parseObject(meter, CommMeter.class);
        if (meterT.getNetEquipmentId() != null && !commNetEquipmentRepository.existsById(meterT.getNetEquipmentId())) {
            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,所属id不存在").build();
        }
        commMeterRepository.save(meterT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateMeter(String meter) {
        CommMeter meterT = JSON.parseObject(meter, CommMeter.class);
        commMeterRepository.save(meterT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deleteMeter(String meter) {
        CommMeter meterT = JSON.parseObject(meter, CommMeter.class);
        commMeterRepository.deleteById(meterT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getMeter(String meter) {
        CommMeter meterT = JSON.parseObject(meter, CommMeter.class);
//        return commNetEquipmentRepository.getOne(commNetEquipmentT.getId());
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commMeterRepository
                .getOne(meterT.getId()))));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }

    @Resource
    private CommValveRepository commValveRepository;

    public Object addValve(String valve) {
        CommValve valveT = JSON.parseObject(valve, CommValve.class);
        if (valveT.getNetEquipmentId() != null && !commNetEquipmentRepository.existsById(valveT.getNetEquipmentId())) {
            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,所属id不存在").build();
        }
        commValveRepository.save(valveT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateValve(String valve) {
        CommValve valveT = JSON.parseObject(valve, CommValve.class);
        commValveRepository.save(valveT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deleteValve(String valve) {
        CommValve valveT = JSON.parseObject(valve, CommValve.class);
        commValveRepository.deleteById(valveT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getValve(String valve) {
        CommValve valveT = JSON.parseObject(valve, CommValve.class);
//        return commNetEquipmentRepository.getOne(commNetEquipmentT.getId());
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commValveRepository
                .getOne(valveT.getId()))));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }

    @Resource
    private CommPanelRepository commPanelRepository;

    public Object addPanel(String panel) {
        CommPanel panelT = JSON.parseObject(panel, CommPanel.class);
        if (panelT.getNetEquipmentId() != null && !commNetEquipmentRepository.existsById(panelT.getNetEquipmentId())) {
            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,所属id不存在").build();
        }
        commPanelRepository.save(panelT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updatePanel(String panel) {
        CommPanel panelT = JSON.parseObject(panel, CommPanel.class);
        commPanelRepository.save(panelT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deletePanel(String panel) {
        CommPanel panelT = JSON.parseObject(panel, CommPanel.class);
        commPanelRepository.deleteById(panelT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getPanel(String panel) {
        CommPanel panelT = JSON.parseObject(panel, CommPanel.class);
//        return commNetEquipmentRepository.getOne(commNetEquipmentT.getId());
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commPanelRepository
                .getOne(panelT.getId()))));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }

    @Resource
    private CommTemperaturepressureRepository commTemperaturepressureRepository;

    public Object addTemperaturepressure(String temperaturepressure) {
        CommTemperaturepressure temperaturepressureT = JSON.parseObject(temperaturepressure, CommTemperaturepressure.class);
//        if (!commTemperaturepressureRepository.existsById(temperaturepressureT.getNetEquipmentId())){
//            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,所属id不存在").build();
//        }
        commTemperaturepressureRepository.save(temperaturepressureT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateTemperaturepressure(String temperaturepressure) {
        CommTemperaturepressure temperaturepressureT = JSON.parseObject(temperaturepressure, CommTemperaturepressure.class);
        commTemperaturepressureRepository.save(temperaturepressureT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deleteTemperaturepressure(String temperaturepressure) {
        CommTemperaturepressure temperaturepressureT = JSON.parseObject(temperaturepressure, CommTemperaturepressure.class);
        commTemperaturepressureRepository.deleteById(temperaturepressureT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getTemperaturepressure(String temperaturepressure) {
        CommTemperaturepressure temperaturepressureT = JSON.parseObject(temperaturepressure, CommTemperaturepressure.class);
//        return commNetEquipmentRepository.getOne(commNetEquipmentT.getId());
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commTemperaturepressureRepository
                .getOne(temperaturepressureT.getId()))));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }


    public Object addService(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        if (commNetServiceT.getEnable() == null) commNetServiceT.setEnable(1);
        if (commNetServiceT.getType() == null) commNetServiceT.setType(NetServiceTypeEnum.主动上报);
        commNetServiceRepository.save(commNetServiceT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateService(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        CommNetService netService = commNetServiceRepository.getOne(commNetServiceT.getId());
        if (commNetServiceT.getEnable() != null
                && commNetServiceT.getEnable() == 1
                && netService.getEnable() != null
                && !netService.getEnable().equals(commNetServiceT.getEnable()))
            meterService.startServer(netService);
        if (commNetServiceT.getEnable() != null
                && commNetServiceT.getEnable() == 0
                && netService.getEnable() != null
                && !netService.getEnable().equals(commNetServiceT.getEnable()))
            meterService.stopServer(netService);
        if (commNetServiceT.getName() != null) netService.setName(commNetServiceT.getName());
        if (commNetServiceT.getPort() != null) netService.setPort(commNetServiceT.getPort());
        if (commNetServiceT.getProtocol() != null) netService.setProtocol(commNetServiceT.getProtocol());
        if (commNetServiceT.getType() != null) netService.setType(commNetServiceT.getType());
        if (commNetServiceT.getEnable() != null) netService.setEnable(commNetServiceT.getEnable());
//        BeanUtils.copyProperties(commNetServiceT,netService);
//        BeanUtils.copyProperties(netService,commNetServiceT);
        commNetServiceRepository.save(netService);
//        commNetServiceRepository.updateNa(commNetServiceT.getId(),commNetServiceT.getName(),commNetServiceT.getPort()
//                ,commNetServiceT.getProtocol(),commNetServiceT.getType()==null?null:commNetServiceT.getType().toString(),commNetServiceT.getEnable());
//        commNetServiceRepository.updateNa(commNetServiceT.getId(),commNetServiceT.getName(),commNetServiceT.getPort()
//                );
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deleteService(String commNetService) {
        CommNetService commNetServiceT = JSON.parseObject(commNetService, CommNetService.class);
        commNetServiceRepository.deleteById(commNetServiceT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    @Value("${dispatch.grpc.local.ip:}")
    private String localIp;

    @SneakyThrows
    public Object getService(String commNetService) {
        List<CommNetService> services = commNetServiceRepository.findAll();
        for (CommNetService service : services) {
            service.setIp(localIp);
            service.setModel(service.getModel());
            service.setNum(netEquService.getServiceOnlineSize(service.getId()));
        }
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(services)))).build();
    }

    @Resource
    private CommNetEquipmentRepository commNetEquipmentRepository;

    public Object addNetEquipment(String commNetEquipment) {
        CommNetEquipment commNetEquipmentT = JSON.parseObject(commNetEquipment, CommNetEquipment.class);
//        if (!commNetServiceRepository.existsById(commNetEquipmentT.getService())) {
//            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,所属协议错误").build();
//        }
        if (repositoryService.getCommNetEquipmentByNetSerial((commNetEquipmentT.getSerial())) != null) {
            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,serial重复").build();
        }
        if (repositoryService.getCommNetEquipmentByIdentity((commNetEquipmentT.getId())) != null) {
            return ResultComm.newBuilder().setCode(ResultConstants.CODE_203).setMsg("失败,标识重复").build();
        }
        commNetEquipmentRepository.save(commNetEquipmentT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateNetEquipment(String commNetEquipment) {
        CommNetEquipment commNetEquipmentT = JSON.parseObject(commNetEquipment, CommNetEquipment.class);
        commNetEquipmentRepository.save(commNetEquipmentT);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object deleteNetEquipment(String commNetEquipment) {
        CommNetEquipment commNetEquipmentT = JSON.parseObject(commNetEquipment, CommNetEquipment.class);
        commNetEquipmentRepository.deleteById(commNetEquipmentT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object removeNetEquipment(String s) {
        log.debug("removeNetEquipment {}", s);
        CommNetEquipment commNetEquipment = JSON.parseObject(s, CommNetEquipment.class);
        NetEqu<String> netEqu = netEquService.getNetEquBySerial(commNetEquipment.getSerial());
        if (netEqu.online()) {
            boolean close = netEqu.close();
            LogUtil.info(commNetEquipment.getSerial(), "手动关闭: {}", close ? "成功" : "失败");
        }
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getNetEquipment(String commNetEquipment) {
        CommNetEquipment commNetEquipmentT = JSON.parseObject(commNetEquipment, CommNetEquipment.class);
        if (commNetEquipmentT.getSortOfDirection() == null) commNetEquipmentT.setSortOfDirection("asc");
        if (commNetEquipmentT.getSortOfField() == null) commNetEquipmentT.setSortOfField("id");
        PageRequest pageRequest = PageRequest.of(commNetEquipmentT.getPage(), commNetEquipmentT.getSize(), Sort.Direction.valueOf(commNetEquipmentT.getSortOfDirection().toUpperCase()), commNetEquipmentT.getSortOfField());
        Page<Object> byCriOfPage = commNetEquipmentRepository.findByCriOfPage(commNetEquipmentT.getId(), commNetEquipmentT.getSerial()
                , commNetEquipmentT.getServiceName(), commNetEquipmentT.getName(), commNetEquipmentT.getModel(), pageRequest);
        Page<CommNetEquipmentVO> commNetEquipmentVOPage = byCriOfPage.map(o -> {
            Object[] o1 = (Object[]) o;
            String online;
            if (o1[3].toString().equals(NetEquTypeEnum.AI控制器.name())) {
                online = netEquService.getAiStormOnOff(o1[2].toString()) ? "在线" : "离线";
            } else {
                NetEqu<String> netEqu = netEquService.getNetEquBySerial(o1[2].toString());
                online = netEqu != null && netEqu.online() ? "在线" : "离线";
            }
            String xName = "";
            if (o1[6] != null) {
                xName = o1[6].toString();
            }
            String name= o1[1] == null ? null : o1[1].toString();
            return new CommNetEquipmentVO(o1[0].toString(), name
                    , o1[2].toString(), NetEquTypeEnum.valueOf(o1[3].toString())
                    , o1[4].toString()
                    , (Integer) o1[5], xName, online);
        });
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commNetEquipmentVOPage)));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }


    public Object addNodeEquipment(String commNodeEqu) {
        CommNodeEqu commNodeEquT = JSON.parseObject(commNodeEqu, CommNodeEqu.class);
        if (commNodeEquT.getType().equalsIgnoreCase("表")) commMeterRepository.save(CommMeter.builder()
                .id(commNodeEquT.getId()).serial(commNodeEquT.getSerial()).netEquipmentId(commNodeEquT.getNetEquId())
                .region(RegionTypeEnum.valueOf(commNodeEquT.getRegion())).model(commNodeEquT.getModel()).port(Integer.valueOf(commNodeEquT.getPort()))
                .sequence(Integer.valueOf(commNodeEquT.getSequence())).statuteCode(Integer.valueOf(commNodeEquT.getStatuteCode())).relayRoute(commNodeEquT.getRelayRoute()).factoryName(commNodeEquT.getFactoryName()).name(commNodeEquT.getName()).build());
        if (commNodeEquT.getType().equalsIgnoreCase("阀")) commValveRepository.save(CommValve.builder()
                .id(commNodeEquT.getId()).serial(commNodeEquT.getSerial()).netEquipmentId(commNodeEquT.getNetEquId())
                .region(RegionTypeEnum.valueOf(commNodeEquT.getRegion())).model(commNodeEquT.getModel()).port(Integer.valueOf(commNodeEquT.getPort()))
                .sequence(Integer.valueOf(commNodeEquT.getSequence())).statuteCode(Integer.valueOf(commNodeEquT.getStatuteCode())).relayRoute(commNodeEquT.getRelayRoute()).factoryName(commNodeEquT.getFactoryName()).name(commNodeEquT.getName()).build());
        if (commNodeEquT.getType().equalsIgnoreCase("面板")) commPanelRepository.save(CommPanel.builder()
                .id(commNodeEquT.getId()).serial(commNodeEquT.getSerial()).netEquipmentId(commNodeEquT.getNetEquId())
                .model(commNodeEquT.getModel()).port(Integer.valueOf(commNodeEquT.getPort()))
                .sequence(Integer.valueOf(commNodeEquT.getSequence())).statuteCode(Integer.valueOf(commNodeEquT.getStatuteCode())).factoryName(commNodeEquT.getFactoryName()).name(commNodeEquT.getName()).build());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object updateNodeEquipment(String commNodeEqu) {
        return addNodeEquipment(commNodeEqu);
    }

    public Object deleteNodeEquipment(String commNodeEqu) {
        CommNodeEqu commNodeEquT = JSON.parseObject(commNodeEqu, CommNodeEqu.class);
        if (commMeterRepository.existsById(commNodeEquT.getId())) commMeterRepository.deleteById(commNodeEquT.getId());
        if (commValveRepository.existsById(commNodeEquT.getId())) commValveRepository.deleteById(commNodeEquT.getId());
        if (commPanelRepository.existsById(commNodeEquT.getId())) commPanelRepository.deleteById(commNodeEquT.getId());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object getNodeEquipment(String commNodeEqu) {
        CommNodeEqu commNodeEquT = JSON.parseObject(commNodeEqu, CommNodeEqu.class);
        if (commNodeEquT.getSortOfDirection() == null) commNodeEquT.setSortOfDirection("asc");
        if (commNodeEquT.getSortOfField() == null) commNodeEquT.setSortOfField("id");
        PageRequest pageRequest = PageRequest.of(commNodeEquT.getPage(), commNodeEquT.getSize(), Sort.Direction.valueOf(commNodeEquT.getSortOfDirection().toUpperCase()), commNodeEquT.getSortOfField());
        Page<Object> byCriOfPage = commNetEquipmentRepository.findByCriOfPageForNodeEqu(commNodeEquT.getId()
                , commNodeEquT.getName(), commNodeEquT.getSerial()
                , commNodeEquT.getModel(), commNodeEquT.getNetEquId(), pageRequest);
        Page<CommNodeEqu> commNetEquipmentVOPage = byCriOfPage.map(o -> {
            Object[] o1 = (Object[]) o;
            CommNodeEqu nodeEqu = new CommNodeEqu();
            nodeEqu.setId(o1[0].toString());
            if (o1[1] != null) nodeEqu.setName(o1[1].toString());
            if (o1[2] != null) nodeEqu.setSerial(o1[2].toString());
            if (o1[3] != null) {
                if ((Short) o1[3] == 1) nodeEqu.setCommunicationType("无线直连");
                if ((Short) o1[3] == 2) nodeEqu.setCommunicationType("NBIOT");
                if ((Short) o1[3] == 3) nodeEqu.setCommunicationType("4G");
//                if ((Short) o1[3] == 4) nodeEqu.setCommunicationType("LoRa");
            }
            if (o1[4] != null) nodeEqu.setRegion(o1[4].toString());
            if (o1[5] != null) nodeEqu.setModel(o1[5].toString());
            if (o1[6] != null) nodeEqu.setPort(o1[6].toString());
            if (o1[7] != null) nodeEqu.setSequence(o1[7].toString());
            if (o1[8] != null) nodeEqu.setStatuteCode(o1[8].toString());
            if (o1[9] != null) nodeEqu.setRelayRoute(o1[9].toString());
            if (o1[10] != null) nodeEqu.setType(o1[10].toString());
            if (o1[11] != null) nodeEqu.setNetEquId(o1[11].toString());
            if (o1[12] != null) nodeEqu.setFactoryName(o1[12].toString());
            return nodeEqu;
        });
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(commNetEquipmentVOPage)));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }


    public Object protocolList(String commNetEquipment) {
        ArrayList<String> list = new ArrayList<>();
        list.add("RUNA_FMU");
        list.add("OTHER_RUNA_FMU");
        list.add("HWS_DEVICE");
        list.add("RUNA_LORA");
        list.add("RUNA_NATIVE");
        list.add("En_Meter");
        list.add("DFS_CLR");
        list.add("HZ_FMU");
        list.add("FK_NBIot");
        list.add("JJN_FMU");
        list.add("DAOHENG_FMU");
        list.add("TIANGANG_FMU");
        list.add("TIANGANG_UDP_FMU");
        list.add("HUANXIANG_FMU");
        list.add("LJE_FMU");
        list.add("LKB_FMU");
        list.add("LC_FMU");
        list.add("ELM_FMU");
        list.add("DB_FMU");
        list.add("DB_2_FMU");
        list.add("HZ_HZ-1_FMU");
        list.add("SWP_DEVICE");
        list.add("USR_G780");
        list.add("AI控制器");
        list.add("JN_TMP");
        list.add("HDB_FMU");
        list.add("AP_FMU");
        list.add("THTF_FMU");
        list.add("QY_FMU");
        list.add("GD_FMU");
        list.add("JP_HD_DTU");
        list.add("FRS_CLIENT");
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(list)));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }

    public Object netEquList(String commNetEquipment) {
        List<CommNetEquipment> all = commNetEquipmentRepository.findAll();
        List<String> list = all.stream().map(CommNetEquipment::getId).collect(Collectors.toList());
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(list)));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }

    public Object netEquTypeList(String commNetEquipment) {
        List<NetEquTypeEnum> list = Arrays.asList(NetEquTypeEnum.values());
        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(list)));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").setData(byteString).build();
    }

    public void addOrder(DxDataPOJO dxDataPOJO) {
        NBOrder nbOrder = new NBOrder();
        if (!StringUtils.isEmpty(dxDataPOJO.getOpen())) nbOrder.setOpen(dxDataPOJO.getOpen());
        if (!StringUtils.isEmpty(dxDataPOJO.getWakeup())) nbOrder.setWakeupCycle(dxDataPOJO.getWakeup());
        if (!StringUtils.isEmpty(dxDataPOJO.getCmdType())) nbOrder.setCmdType(dxDataPOJO.getCmdType());
        if (!StringUtils.isEmpty(dxDataPOJO.getCompensation())) nbOrder.setCompensation(dxDataPOJO.getCompensation());
        if (!StringUtils.isEmpty(dxDataPOJO.getAcquisition())) nbOrder.setAcquisition(dxDataPOJO.getAcquisition());
        commNbCmdService.addNbOrder(dxDataPOJO.getIdentity(), nbOrder);

        AsynResult asynResult = new AsynResult();
        asynResult.setCode(ResultConstants.CODE_200);
        asynResult.setMsg(MqttUtil.successString);
        asynResult.setTask(dxDataPOJO.getTask());
        asynResult.setHoldInfo(dxDataPOJO.getHoldInfo());
        asynResult.setIdentity(dxDataPOJO.getIdentity());
        MqttUtil.send(MqttUtil.topicOfNoneContent, asynResult);

    }

    public Object sendDxOfExtra(String dxDataPOJOT) {
        DxDataPOJO dxDataPOJO = JSON.parseObject(dxDataPOJOT, DxDataPOJO.class);
        executor.execute(() -> addOrder(dxDataPOJO));
//        ByteString byteString = ByteString.copyFrom(Objects.requireNonNull(JSON.toJSONBytes(list)));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }


    public Object readFmuNow(String pojo) {
        log.info("业务请求—立即抄表 request:{}", JSON.toJSONString(pojo));
        ReadFmuNowPOJO p = JSON.parseObject(pojo, ReadFmuNowPOJO.class);
        executor.execute(() -> interfaceService.readFmuNow(p.getIdentity(), p.getTask(), p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object sentEquArchive(String pojo) {
        log.info("业务请求—网络设备下发档案开始  request:{}", JSON.toJSONString(pojo));
        SentEquArchivePOJO p = JSON.parseObject(pojo, SentEquArchivePOJO.class);
        executor.execute(() -> interfaceService.rccSentEquArchive(p.getIdentity(), p.getTask(), p.getArchives(), p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object clearEquArchive(String pojo) {
        log.info("业务请求—清除档案  request:{}", JSON.toJSONString(pojo));
        BasePOJO p = JSON.parseObject(pojo, BasePOJO.class);
        executor.execute(() -> interfaceService.rccClearEquArchive(p.getIdentity(), p.getTask(), p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readEquArchive(String pojo) {
        log.info("业务请求—网络设备读档案  request:{}", JSON.toJSONString(pojo));
        ReadEquArchivePOJO p = JSON.parseObject(pojo, ReadEquArchivePOJO.class);
        executor.execute(() -> interfaceService.readEquArchive(p.getIdentity(), p.getTask(), p.getIndexes(), p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object setMeterReadingCycleParameter(String pojo) {
        log.info("业务请求—抄表周期设定  request:{}", JSON.toJSONString(pojo));
        SetMeterReadingCycleParameterPOJO p = JSON.parseObject(pojo, SetMeterReadingCycleParameterPOJO.class);
//        SetMeterReadingCycleParameterPOJO setMeterReadingCycleParameterPOJO = JSON.parseObject(request.getJson(), SetMeterReadingCycleParameterPOJO.class);
        GatewayDeviceParameter gatewayDeviceParameter = new GatewayDeviceParameter();
        if (p.getMinuteOfCollect() != null) {
            gatewayDeviceParameter.setMinuteOfCollectForHouse(p.getMinuteOfCollect());
            gatewayDeviceParameter.setMinuteOfCollectForBuild(p.getMinuteOfCollect());
            gatewayDeviceParameter.setMinuteOfUploadForBuild(p.getMinuteOfUpload());
            gatewayDeviceParameter.setMinuteOfUploadForHouse(p.getMinuteOfUpload());
        } else {
            gatewayDeviceParameter.setMinuteOfCollectForHouse(p.getMinuteOfCollectForHouse());
            gatewayDeviceParameter.setMinuteOfCollectForBuild(p.getMinuteOfCollectForBuild());
            gatewayDeviceParameter.setMinuteOfUploadForBuild(p.getMinuteOfUploadForBuild());
            gatewayDeviceParameter.setMinuteOfUploadForHouse(p.getMinuteOfUploadForHouse());
            if (p.getAcquisitionCycleOfMinutes()!=null){
                gatewayDeviceParameter.setMinuteOfCollectForHouse(p.getAcquisitionCycleOfMinutes());
            }
        }
        executor.execute(() ->
                interfaceService.setMeterReadingCycleParameter(p.getIdentity()
                , p.getTask()
                , gatewayDeviceParameter
                , p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readMeterReadingCycleParameter(String pojo) {
        log.info("业务请求—读抄表周期  request:{}", JSON.toJSONString(pojo));
        BasePOJO p = JSON.parseObject(pojo, BasePOJO.class);
        executor.execute(() -> interfaceService.readMeterReadingCycleParameter(p.getIdentity(), p.getTask(), p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object setFlowLimit(String pojo) {
        log.info("业务请求—流量超限设定  request:{}", JSON.toJSONString(pojo));
        SetFlowLimitPOJO p = JSON.parseObject(pojo, SetFlowLimitPOJO.class);
        executor.execute(() -> interfaceService.flowLimitSetting(p.getIdentity(), p.getTask(), p.getValue(), p.getPriorityOfSetFlowLimit(), p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readMeter(String dxDataPOJOT) {
        log.debug("业务请求—网络设备抄热表 request:{}", dxDataPOJOT);
        LogUtil.getLogAndInfo("readMeter", "抄表", dxDataPOJOT);
        ReadMeterPOJO readMeterPOJO = JSON.parseObject(dxDataPOJOT, ReadMeterPOJO.class);
        log.info("业务请求—网络设备抄热表 {}", readMeterPOJO.getTask() );
        log.info("业务请求—网络设备抄热表 {} 读表 {} 条", readMeterPOJO.getTask(), readMeterPOJO.getMeters() == null ? 0 : readMeterPOJO.getMeters().size() );
        executor.execute(() -> interfaceService.readMeter(readMeterPOJO.getTask(),
                readMeterPOJO.getHoldInfo(), readMeterPOJO.getMeters(), readMeterPOJO.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readMeterNew(String s) {
        log.debug("业务请求—抄表: {}", JSON.toJSONString(s));
        LogUtil.getLogAndInfo("readMeter", "抄表", s);
        ObjectMapper objectMapper = new ObjectMapper();
        executor.execute(() -> {
            Command<List<ReadMeter>> command;
            try {
                command = objectMapper.readValue(s, new TypeReference<Command<List<ReadMeter>>>() {});
                Map<String, List<MeterBase>> meterMap = command.getParams().stream().collect(Collectors.groupingBy(ReadMeter::getProtoType, Collectors.mapping(ReadMeter::getData, Collectors.toList())));
                for (String protoType : meterMap.keySet()) {
                    List<MeterBase> meterBases = meterMap.get(protoType);
                    switch (protoType) {
                        case "RUNA":
                            interfaceService.readRunaMeters(meterBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;
                    }
                }
            } catch (IOException e) {
                log.error("", e);
            }

        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readValveNew(String s) {
        log.info("业务请求—抄阀: {}", s);
        LogUtil.getLogAndInfo("readValve", "抄阀", s);
        ObjectMapper objectMapper = new ObjectMapper();
        executor.execute(() -> {
            Command<List<ReadValve>> command;
            try {
                command = objectMapper.readValue(s, new TypeReference<Command<List<ReadValve>>>() {});
                Map<String, List<ValveBase>> valveMap = command.getParams().stream().collect(Collectors.groupingBy(ReadValve::getProtoType, Collectors.mapping(ReadValve::getData, Collectors.toList())));
                for (String protoType : valveMap.keySet()) {
                    List<ValveBase> valveBases = valveMap.get(protoType);
                    switch (protoType) {
                        case "RUNA":
                            interfaceService.readRunaValves(valveBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;
                    }
                }
            } catch (IOException e) {
                log.error("", e);
            }

        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readValve(String dxDataPOJOT) {
        log.info("业务请求—抄阀 request:{}", JSON.toJSONString(dxDataPOJOT));
        LogUtil.getLogAndInfo("readValve", "抄阀", dxDataPOJOT);
        ReadValvePOJO p = JSON.parseObject(dxDataPOJOT, ReadValvePOJO.class);
        executor.execute(() -> interfaceService.readValve(p.getTask(), p.getHoldInfo(), p.getValves(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object readElecMeter(String dxDataPOJOT) {
        log.info("业务请求—抄电表 request:{}", JSON.toJSONString(dxDataPOJOT));
        BasePOJO p = JSON.parseObject(dxDataPOJOT, BasePOJO.class);
        executor.execute(() -> interfaceService.rccReadNodeDataOfElec(p.getIdentity(), p.getTask(), p.getHoldInfo()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }



    public Object readPanel(String dxDataPOJOT) {
        log.info("业务请求—抄温度面板 request:{}", JSON.toJSONString(dxDataPOJOT));
        ReadPanelPOJO p = JSON.parseObject(dxDataPOJOT, ReadPanelPOJO.class);
        executor.execute(() -> interfaceService.readPanel(p.getTask(), p.getHoldInfo(), p.getPanels(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object buildValveParam(String dxDataPOJOT) {
        log.info("业务请求—读楼站阀门参数 request:{}", JSON.toJSONString(dxDataPOJOT));
        BuildValveParamPOJO p = JSON.parseObject(dxDataPOJOT, BuildValveParamPOJO.class);
        int mo;
        if (p.getModel().toString().equalsIgnoreCase("PID")) {
            mo = 3;
        } else if (p.getModel().toString().equalsIgnoreCase("单元调控策略")) {
            mo = 1;
        } else if (p.getModel().toString().equalsIgnoreCase("开度限值")) {
            mo = 4;
        } else {
            mo = 0;
        }
        executor.execute(() -> interfaceService.buildValveParam(p.getTask(), p.getValves(), mo, p.getHoldInfo(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();

    }

    public Object buildValveControl(String dxDataPOJOT) {
        log.info("业务请求—楼站(户)阀门控制 request:{}", JSON.toJSONString(dxDataPOJOT));
        BuildValveControlPOJO p = JSON.parseObject(dxDataPOJOT, BuildValveControlPOJO.class);
        executor.execute(() -> interfaceService.valveControl(p.getTask(), p.getHoldInfo(), p.getValveControlList(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }



    public Object valveControl(String s) {
        log.info("业务请求—阀门控制 request:{}", JSON.toJSONString(s));
        ObjectMapper objectMapper = new ObjectMapper();
        executor.execute(() -> {
            Command<List<ControlValve>> command;
            try {
                command = objectMapper.readValue(s, new TypeReference<Command<List<ControlValve>>>() {});
                Map<String, List<ValveBase>> valveMap = command.getParams().stream().collect(Collectors.groupingBy(ControlValve::getProtoType, Collectors.mapping(ControlValve::getData, Collectors.toList())));
                for (String protoType : valveMap.keySet()) {
                    List<ValveBase> valveBases = valveMap.get(protoType);
                    switch (protoType) {
                        case "RUNA":
                            interfaceService.runaValveControl(valveBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;
                        case "FEI_KONG":
                            interfaceService.flightControlValveControl(valveBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;
                        case "HEI_MA_YI":
                            interfaceService.hmyValveControl(valveBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;
                        case "ZHE_DA":
                            interfaceService.zheDaValveControl(valveBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;
                        case "YI_LIN":
                            interfaceService.yiLinValveControl(valveBases, command.getTask(), command.getHoldInfo(), command.getPriority());
                            break;

                    }
                }
            } catch (IOException e) {
                log.error("", e);
            }

        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object buildValveControlOfOpen(String dxDataPOJOT) {
        log.info("业务请求—网络设备下阀门开度上下限控制 request:{}", JSON.toJSONString(dxDataPOJOT));
        BuildValveControlOfOpenVO p = JSON.parseObject(dxDataPOJOT, BuildValveControlOfOpenVO.class);
        executor.execute(() -> interfaceService.buildValveOpenLimit(p.getTask(), p.getHoldInfo(), p.getValveOpenLimitList(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object valveTemperatureControl(String dxDataPOJOT) {
        log.info("业务请求—温度上下限控制 request:{}", JSON.toJSONString(dxDataPOJOT));
        ValveTemperatureControlPOJO p = JSON.parseObject(dxDataPOJOT, ValveTemperatureControlPOJO.class);
        executor.execute(() -> interfaceService.valveTemperatureControl(p.getTask(), p.getHoldInfo(), p.getValveTemperatureLimitList(), p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object valveTemperatureComp(String dxDataPOJOT) {
        log.info("业务请求—户阀温度补偿 request:{}", JSON.toJSONString(dxDataPOJOT));
        ValveTemperatureCompPOJO p = JSON.parseObject(dxDataPOJOT, ValveTemperatureCompPOJO.class);
        executor.execute(() -> {
            for (ValveTemperatureComp valveTemperatureComp : p.getValveTemperatureCompList()) {
                interfaceService.valveTemperatureComp(p.getTask(), p.getHoldInfo(), valveTemperatureComp.getValve(), valveTemperatureComp.getCompensation(), p.getPriority());
            }
        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object buildValveModel(String dxDataPOJOT) {
        log.info("业务请求—楼站阀门模式本地/远程修改 request:{}", JSON.toJSONString(dxDataPOJOT));
        BuildValveModelPOJO p = JSON.parseObject(dxDataPOJOT, BuildValveModelPOJO.class);
        executor.execute(() -> {
            for (ValveModel valveModel : p.getValveModelList()) {
                interfaceService.buildValveModel(p.getTask(), p.getHoldInfo(), valveModel.getValve(), valveModel.getModel() == ValveModel.ModelEnum.远程, p.getPriority());
            }
        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object buildValveModelOfTimeScheme(String dxDataPOJOT) {
        log.info("业务请求—网络设备下阀门时段方案控制 request:{}", JSON.toJSONString(dxDataPOJOT));
        BuildValveModelOfTimeSchemePOJO p = JSON.parseObject(dxDataPOJOT, BuildValveModelOfTimeSchemePOJO.class);
//        interfaceService.rccReadNodeData(readMeterPOJO.getTask(), readMeterPOJO.getHoldInfo(), readMeterPOJO.getMeters(), EquData.EquDataType.METER, readMeterPOJO.getPriority());
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object buildValveModelOfPID(String dxDataPOJOT) {
        log.info("业务请求—设置PID request:{}", JSON.toJSONString(dxDataPOJOT));
        BuildValveModelOfPIDPOJO p = JSON.parseObject(dxDataPOJOT, BuildValveModelOfPIDPOJO.class);
        executor.execute(() -> {
            for (ValvePID valvePID : p.getValvePIDList()) {
                interfaceService.buildValveModelOfPID(p.getTask(), p.getHoldInfo(), valvePID, p.getPriority());
            }
        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object aiDownloadFile(String dxDataPOJOT) {
        log.info("业务请求—AI控制器文件下载 request:{}", JSON.toJSONString(dxDataPOJOT));
        AiDownloadFile p = JSON.parseObject(dxDataPOJOT, AiDownloadFile.class);
        executor.execute(() -> interfaceService.meterDownloadFile(p.getTask(), p.getHoldInfo(), p));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object aiDownloadFileBatch(String pojo) {
        log.info("业务请求—AI控制器文件下载批量 request:{}", JSON.toJSONString(pojo));
        AiDownloadFileListVO p = JSON.parseObject(pojo, AiDownloadFileListVO.class);
        executor.execute(() -> {
            for (AiDownloadFile aiDownloadFile : p.getAiDownloadFileList()) {
                interfaceService.meterDownloadFile(p.getTask(), p.getHoldInfo()
                        , aiDownloadFile);
            }
        });
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object aiCtrlTemperature(String dxDataPOJOT) {
        log.info("业务请求—AI控制器温度上下限修改 request:{}", JSON.toJSONString(dxDataPOJOT));
        ValveTemperatureControlOfAiStorm p = JSON.parseObject(dxDataPOJOT, ValveTemperatureControlOfAiStorm.class);
        executor.execute(() -> interfaceService.valveTemperatureControlOfAiStorm(p, p.getPriority()));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object houseValveSetTempSn(String param) {
        log.info("业务请求—AI控制器单一户阀关联面板编号 request:{}", JSON.toJSONString(param));
        HouseValveControlPOJO houseValveControlPOJO = JSON.parseObject(param, HouseValveControlPOJO.class);
        executor.execute(() -> interfaceService.houseValveSetTempSnOfAiStorm(houseValveControlPOJO));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object houseValveSetValveTempSn(String param) {
        log.info("业务请求—AI控制器全部户阀关联面板编号 request:{}", JSON.toJSONString(param));
        HouseValveControlPOJO houseValveControlPOJO = JSON.parseObject(param, HouseValveControlPOJO.class);
        executor.execute(() -> interfaceService.houseValveSetValveTempSnOfAiStorm(houseValveControlPOJO));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object houseValveSetRl(String param) {
        log.info("业务请求—AI控制器户阀写入累计热量 request:{}", JSON.toJSONString(param));
        HouseValveControlPOJO houseValveControlPOJO = JSON.parseObject(param, HouseValveControlPOJO.class);
        executor.execute(() -> interfaceService.houseValveSetRlOfAiStorm(houseValveControlPOJO));
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }


    public Object flightControlValveOpen(String param) {
        log.debug("飞控阀门批量开度控制: {}", param);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    public Object flightControlValveOutTemperature(String param) {
        log.debug("飞控阀门批量回温控制: {}", param);
        return ResultComm.newBuilder().setCode(ResultConstants.CODE_200).setMsg("成功").build();
    }

    @Resource
    private EquInstructService equInstructService;

    public Object sendInstruct(String param) {
        log.info("设备指令下发: {}", param);
        EquInstruct equInstruct = JSON.parseObject(param, EquInstruct.class);
        Object result = equInstructService.request(equInstruct);
        log.info("result: {}", JSON.toJSONString(result));
        return result;
    }

    @Resource
    private CommNetEquipmentCache commNetEquipmentCache;
    @Resource
    private CommMeterCache commMeterCache;
    @Resource
    private CommValveCache commValveCache;
    @Resource
    private CommPanelCache commPanelCache;

    public void syncNetEqu(String s) {
        log.debug("syncNetEqu: {}", s);
        List<String> ids = JSON.parseObject(s, List.class);
        commNetEquipmentCache.remove(ids);
    }

    public void syncMeter(String s) {
        log.debug("syncMeter: {}", s);
        List<String> ids = JSON.parseObject(s, List.class);
        commMeterCache.remove(ids);
    }

    public void syncValve(String s) {
        log.debug("syncValve: {}", s);
        List<String> ids = JSON.parseObject(s, List.class);
        commValveCache.remove(ids);

    }

    public void syncPanel(String s) {
        log.debug("syncPanel: {}", s);
        List<String> ids = JSON.parseObject(s, List.class);
        commPanelCache.remove(ids);
    }



}
